/**
 * 找回密码
 */
CDT = {
	smsSent: false,
	countDownNum:0,
	counter:void 0,
	formSent:true
};
$(function(){
	
	//获取验证码
	$('#btncaptcha').click(function(){
		CDT.smsSent = false;
		if($('#mobile').val().length !=11){
			alert("手机号错误");
			return;
		}
		// 当其他校验通过之后才可以发送
//		if (!validator.form()) {
//			return;
//		}
		var mobile = $('#mobile').val(),nick = $('#nick').val();
		Tr.post('/findPass/sendSms', {
			'mobile':mobile,
			authenticityToken: $('input[name="authenticityToken"]').val()
		}, function(data) {
			if (data.code == 800101) {
				alert(data.msg);
				return;
			}
			if (data.code == 555){
				alert('短信发送失败，请重试！');
			}
			if (data.code != 200) {
				return;
			}
			$('#btncaptcha').attr('disabled','disabled');
			CDT.countDownNum = 60;
			alert('验证短信已发送，请稍等！');
			CDT.counter = setInterval(countingFunc,1000);
			CDT.smsSent = true;
		});
	});
	$("#modifyPass").click(function(){
		var mobile=$('#mobile').val();
		var smsValidate=$('#smsValidate').val();
		var password=$('#password').val();
		var password2=$('#password2').val();
		if($('#mobile').val()==''){
			alert("手机号错误");
			return;
		}
		if($('#mobile').val().length !=11){
			alert("手机号错误");
			return;
		}
		if($('#smsValidate').val()==''){
			alert("验证码不能为");
			return;
		}
		if($('#password').val()==''){
			alert("请输入密码");
			return;
		}
		if($('#password2').val()==''){
			alert("请输入确认密码");
			return;
		}
		if($('#password2').val()!=$('#password').val()){
			alert("两次密码输入不一致");
			return;
		}
		$.ajax({
			type:'post',
			url:'/doFindPass',
			data:{mobile:mobile,smsValidate:smsValidate,
				password:password,password2:password2,
				authenticityToken: $('input[name="authenticityToken"]').val()},
			success:function(data){
				if(data.code==599){
					alert(data.msg);
				}
				else{
					alert("找回成功");
					//成功返回登录页
					window.location.href="/login";
				}
			}
		})
	})
	
	
})
function countingFunc(){
	if(CDT.countDownNum>0){
		$('#btncaptcha').val(--CDT.countDownNum+'秒后可重发');
	}else{
		$('#btncaptcha').removeAttr('disabled').val('重新发送');
		clearInterval(CDT.counter);
		CDT.counter = void 0;
		CDT.countDownNum = 0;
	}
}
	